﻿using lumo.display.animation2D;
using lumo.display.object2D;
using lumo.scene;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;

namespace game.scene
{

    public class SceneGameOver : IScene
    {

        protected Sprite _Sprite;
        protected IAnimation2D _Animation;

        public void Start(lumo.LumoComponent component)
        {
            MediaPlayer.Play(component.Content.Load<Song>("Audio/SE/GameOver"));
            MediaPlayer.IsRepeating = false;
            _Sprite = new Sprite(
                component.Content.Load<Texture2D>("Graphics/Pictures/GameOver")
            );
            _Sprite.Color = Color.Black;
            _Animation = new ColorAnimation2D(
                Color.White, 1000.0f, lumo.Smooth.Arrival, lumo.Loop.None, _Sprite
            );
        }

        public void Update(lumo.LumoComponent component)
        {
            _Animation.Update(component);
            if (_Animation.Finished)
                if (Global.Keypad.GetKey(Keys.Enter).Triggered)
                {
                    SerialAnimation2D serialAnimation =
                        new SerialAnimation2D(_Sprite);
                    serialAnimation.Add(new ColorAnimation2D(Color.Black, 1000.0f, lumo.Smooth.Start));
                    serialAnimation.Add(new LambdaAnimation2D(Action => component.Scene = new SceneTitle(this)));
                    _Animation = serialAnimation;
                }
        }

        public void Draw(lumo.LumoComponent component)
        {
            component.SpriteBatch.Begin(SpriteSortMode.Immediate, null, null, null, null, null, Global.ScreenMatrix);
            _Sprite.Draw(component.SpriteBatch);
            component.SpriteBatch.End();
        }

        public void Terminate(lumo.LumoComponent component)
        {
        }

    }

}